package reflect;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @author wangyingjie
 * @date 2018年09月28日17:10:01
 * @remark AOP动态代理对应的invocationHandler
 */
public class SuperPersonInvocationHandler implements InvocationHandler {

    /**
     * 被代理的对象
     */
    private SuperPerson target;

    public void setTarget(SuperPerson target) {
        this.target = target;
    }

    /**
     * 通过反射增强调用方法
     * @param proxy
     * @param method
     * @param args
     * @return
     * @throws Throwable
     */
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        PersonUtil util = new PersonUtil();
        util.method1();
        Object result = method.invoke(target, args);
        util.method2();
        return result;
    }
}
